package cn.hml.org.service.impl;

import cn.hml.basic.PageList;
import cn.hml.org.mapper.DepartmentMapper;
import cn.hml.org.service.IDepartmentService;
import cn.hml.org.domain.Department;
import cn.hml.org.query.DepartmentQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public List<Department> findAll() {
        return departmentMapper.findAll();
    }

    @Override
    public Department findOne(Long id) {
        return departmentMapper.findOne(id);
    }

    @Override
    @Transactional
    public void add(Department department) {
        departmentMapper.add(department);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    public PageList<Department> pageQuery(DepartmentQuery departmentQuery) {
        Long count = departmentMapper.count();
        List<Department> rows = departmentMapper.pageQuery(departmentQuery);
        return new PageList<Department>(count,rows);
    }
}
